//
//  MyAdSwitchCell.swift
//  Automobile
//
//  Created by erkebulan elzhan on 8/22/20.
//  Copyright © 2020 erkebulan elzhan. All rights reserved.
//

import UIKit


final class MyAdSwitchCell: UITableViewCell, ConfigurableCell {
    
    private lazy var titleLbl: UILabel = {
        let lbl = UILabel()
        lbl.sizeToFit()
        lbl.textColor = .darkBlueColor
        lbl.font = .systemFont(ofSize: 17, weight: .regular)
        return lbl
    }()
    
    private lazy var priceLbl: UILabel = {
        let lbl = UILabel()
        lbl.textColor = .darkGray
        lbl.font = .systemFont(ofSize: 13, weight: .regular)
        return lbl
    }()
    
    private lazy var iconView: UIImageView = {
        let icon = UIImageView()
        icon.contentMode = .scaleAspectFit
        return icon
    }()
    
    private lazy var switchView: UISwitch = {
        let switchView = UISwitch()
        return switchView
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.addViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func configure(data: MyAdViewModel.MyAdSwitchData?, index: Int) {
        self.titleLbl.text = data?.text
        self.priceLbl.text = "\(data!.price)₸ в день"
        self.iconView.image = data?.icon
    }
    func returnData() -> MyAdViewModel.MyAdSwitchData? { return nil }
    
    
    private func addViews() {
        contentView.addSubview(titleLbl)
        contentView.addSubview(priceLbl)
        contentView.addSubview(iconView)
        contentView.addSubview(switchView)
        
        switchView.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.trailing.equalToSuperview().inset(16)
            make.width.equalTo(48)
            make.height.equalTo(24)
        }
        titleLbl.snp.makeConstraints { (make) in
            make.height.equalTo(18)
            make.top.equalToSuperview().inset(12)
            make.leading.equalToSuperview().inset(16)
        }
        iconView.snp.makeConstraints { (make) in
            make.width.height.equalTo(16)
            make.leading.equalTo(titleLbl.snp.trailing).offset(6)
            make.centerY.equalTo(titleLbl)
        }
        priceLbl.snp.makeConstraints { (make) in
            make.height.equalTo(24)
            make.top.equalTo(titleLbl.snp.bottom)
            make.bottom.equalToSuperview().offset(-7)
            make.leading.equalToSuperview().inset(16)
        }
    }
}
